﻿/**  版本信息模板在安装目录下，可自行修改。
* Map_Card_Info.cs
*
* 功 能： N/A
* 类 名： Map_Card_Info
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2018/7/31 22:14:09   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SQLite;
using AgvDemo;
//using Maticsoft.DBUtility;//Please add references
namespace AgvDemo.DAL
{
    /// <summary>
    /// 数据访问类:Map_Card
    /// </summary>
    public partial class Map_Card
    {
        public Map_Card()
        { }
        #region  BasicMethod

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return DbHelperSQLite.GetMaxID("card_id", "Map_Card");
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int card_id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from Map_Card");
            strSql.Append(" where card_id=@card_id ");
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@card_id", DbType.Int32,4)         };
            parameters[0].Value = card_id;

            return DbHelperSQLite.Exists(strSql.ToString(), parameters);
        }


        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(AgvDemo.Model.Map_Card model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Map_Card(");
            strSql.Append("card_id,card_x,card_y)");
            strSql.Append(" values (");
            strSql.Append("@card_id,@card_x,@card_y)");
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@card_id", DbType.Int32,4),
                    new SQLiteParameter("@card_x", DbType.Int32,4),
                    new SQLiteParameter("@card_y", DbType.Int32,4)};
            parameters[0].Value = model.card_id;
            parameters[1].Value = model.card_x;
            parameters[2].Value = model.card_y;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(AgvDemo.Model.Map_Card model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update Map_Card set ");
            strSql.Append("card_x=@card_x,");
            strSql.Append("card_y=@card_y");
            strSql.Append(" where card_id=@card_id ");
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@card_x", DbType.Int32,4),
                    new SQLiteParameter("@card_y", DbType.Int32,4),
                    new SQLiteParameter("@card_id", DbType.Int32,4)};
            parameters[0].Value = model.card_x;
            parameters[1].Value = model.card_y;
            parameters[2].Value = model.card_id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int card_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Map_Card ");
            strSql.Append(" where card_id=@card_id ");
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@card_id", DbType.Int32,4)         };
            parameters[0].Value = card_id;

            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string card_idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from Map_Card ");
            strSql.Append(" where card_id in (" + card_idlist + ")  ");
            int rows = DbHelperSQLite.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public AgvDemo.Model.Map_Card GetModel(int card_id)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select card_id,card_x,card_y from Map_Card ");
            strSql.Append(" where card_id=@card_id ");
            SQLiteParameter[] parameters = {
                    new SQLiteParameter("@card_id", DbType.Int32,4)         };
            parameters[0].Value = card_id;

            AgvDemo.Model.Map_Card model = new AgvDemo.Model.Map_Card();
            DataSet ds = DbHelperSQLite.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public AgvDemo.Model.Map_Card DataRowToModel(DataRow row)
        {
            AgvDemo.Model.Map_Card model = new AgvDemo.Model.Map_Card();
            if (row != null)
            {
                if (row["card_id"] != null && row["card_id"].ToString() != "")
                {
                    model.card_id = int.Parse(row["card_id"].ToString());
                }
                if (row["card_x"] != null && row["card_x"].ToString() != "")
                {
                    model.card_x = int.Parse(row["card_x"].ToString());
                }
                if (row["card_y"] != null && row["card_y"].ToString() != "")
                {
                    model.card_y = int.Parse(row["card_y"].ToString());
                }
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select card_id,card_x,card_y ");
            strSql.Append(" FROM Map_Card ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM Map_Card ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQLite.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.card_id desc");
            }
            strSql.Append(")AS Row, T.*  from Map_Card T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQLite.Query(strSql.ToString());
        }

        /*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SQLiteParameter[] parameters = {
					new SQLiteParameter("@tblName", DbType.VarChar, 255),
					new SQLiteParameter("@fldName", DbType.VarChar, 255),
					new SQLiteParameter("@PageSize", DbType.Int32),
					new SQLiteParameter("@PageIndex", DbType.Int32),
					new SQLiteParameter("@IsReCount", DbType.bit),
					new SQLiteParameter("@OrderType", DbType.bit),
					new SQLiteParameter("@strWhere", DbType.VarChar,1000),
					};
			parameters[0].Value = "Map_Card";
			parameters[1].Value = "card_id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQLite.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

        #endregion  BasicMethod
        #region  ExtensionMethod

        #endregion  ExtensionMethod
    }
}

